import http from "../service/http.js"
export const aftersaleModule = {
	// 售后模块
	state: {
		
		goodList:[
			
		],
		serveTypes:[
			// 服务类型
			{
				label: '退款',
				val:0
			},{
				label: '退货',
				val:1
			},{
				label: '换货',
				val:2
			},
		],
		aftersaleStatus: [
			// 售后状态分类
			// 服务单状态:0.待处理，1.待买家发货，2.待商家确认收货，3.待商家发新货（换货才有的状态），4.待用户收货（换货才有的状态），5.已完成，6.已拒绝
			{
				label: '待审核',
				val:0
			},
			{
				label: '审核通过',
				val:1
			},
			{
				label: '待商家收货',
				val:2
			},
			{
				label: '待发新货',
				val:3
			},
			{
				label: '待用户收货',
				val:4
			},
			{
				label: '已完成',
				val:5
			},
			{
				label: '审核不通过',
				val:6
			}
		],

		aftersaleOrderInfo: {
			// 申请退货的订单

			// address: "榄树排东街"
			// beginTime: null
			// billType: 0
			// billwayNo: null
			// buyAddressId: null
			// buyId: 3
			// buyNickname: "18202074132"
			// calcelDetaila: null
			// calcelId: null
			// city: "广州市"
			// county: "黄埔区"
			// createBy: "18202074132"
			// createTime: "2021-01-13 09:07:24"
			// endTime: null
			// fastMail: null
			// goodsCounts: 1
			// goodsList: [{…}]
			// goodsPrice: 0
			// id: "19"
			// iphone: "18202074132"
			// jpOrdersInvoice: null
			// logList: null
			// messageInfo: ""
			// orderFreight: null
			// orderNo: "6748302413674840064"
			// orderPrice: 0.01
			// orderState: 0
			// params: {}
			// payType: 0
			// pickType: 0
			// province: "广东省"
			// remark: null
			// returnType: 0
			// searchValue: null
			// stockType: 0
			// takeName: null
			// updateBy: ""
			// updateTime: null

		},

	},
	mutations: {

		// setOrderList(state, OrderList) {

		// 	state.OrderList = OrderList;
		// },
		setAftersaleOrderInfo(state, aftersaleOrderInfo) {
			aftersaleOrderInfo.goodsList = aftersaleOrderInfo.goodsList.map(item => {
				item.check = false
				return item
			})
			state.aftersaleOrderInfo = aftersaleOrderInfo;
			state.goodList=aftersaleOrderInfo.goodsList
		},


	},
	getters: {

	},
	actions: {

		getOrderRefundList: async function({
				commit,
				state
			},
			params
		) {

			return await new Promise((resolve, reject) => {

				http.get('/refund/list',params).then(res => {

					console.log("获取订单售后列表成功", res)
					// let data = res.data.data


					resolve(res)

				}).catch(err => {
					console.log("获取订单售后列表失败", err)
					reject(err)
				})
			})
		},
		
		
		getOrderRefundInfo: async function({
				commit,
				state
			}, params
			// {
			// id 
			//获取订单售后信息
			// }
		) {
		
			return await new Promise((resolve, reject) => {
		
				http.get(`/refund/getInfo/${params.id}`).then(res => {
		
					console.log("获取订单售后信息成功", res)
					// let data = res.data.data
		
		
					resolve(res)
		
				}).catch(err => {
					console.log("获取订单售后信息失败", err)
					reject(err)
				})
			})
		},
		
		
		addRefund: async function({ //添加售后服务单
				commit,
				state
			}, params
			// {
			//   "applyMoney": 0,
			//   "barterAddressId": 0,
			//   "barterBillwayNo": "string",
			//   "barterFastMail": "string",
			//   "beginTime": "string",
			//   "createBy": "string",
			//   "createTime": "2021-01-15T02:46:39.772Z",
			//   "disposeDate": "string",
			//   "disposeUserId": 0,
			//   "endTime": "string",
			//   "freightType": 0,
			//   "id": 0,
			//   "identifyDate": "2021-01-15T02:46:39.772Z",
			//   "identifyUserId": 0,
			//   "orderNo": "string",
			//   "orderPrise": 0,
			//   "params": {},
			//   "refundAddressId": 0,
			//   "refundBillwayNo": "string",
			//   "refundDescribe": "string",
			//   "refundFastMail": "string",
			//   "refundGoods": [
			//     {
			//       "createBy": "string",
			//       "createTime": "2021-01-15T02:46:39.772Z",
			//       "goodsId": 0,
			//       "goodsName": "string",
			//       "goodsPic": "string",
			//       "goodsPrise": 0,
			//       "id": 0,
			//       "orderNo": "string",
			//       "params": {},
			//       "refundCount": 0,
			//       "refundMoney": 0,
			//       "remark": "string",
			//       "searchValue": "string",
			//       "updateBy": "string",
			//       "updateTime": "2021-01-15T02:46:39.772Z"
			//     }
			//   ],
			//   "refundImg": "string",
			//   "refundMoney": 0,
			//   "refundNo": "string",
			//   "refundReason": "string",
			//   "refundState": 0,
			//   "refundUserid": 0,
			//   "rejectReason": "string",
			//   "remark": "string",
			//   "searchValue": "string",
			//   "serveType": 0,
			//   "updateBy": "string",
			//   "updateTime": "2021-01-15T02:46:39.772Z"
			// }


		) {
			// console.log("params", params)
			// commit("setOrderFrom", params)
			return await new Promise((resolve, reject) => {

				http.post('/refund/add', params).then(res => {

					console.log("添加售后服务单信息成功", res)
					let data = res.data.data
					// dispatch("getOrderList")
					resolve(data)

				}).catch(err => {
					console.log("添加售后服务单信息失败", err)
					reject(err)
				})
			})
		},
		editRefundState: async function({ //买家操作服务单
				commit,
				state
			}, params
			// {
			 // "barterAddressId": 0,
			 //  "billwayNo": "string",
			 //  "fastMail": "string",
			 //  "freightType": 0,
			 //  "orderNo": "string",
			 //  "refundAddressId": 0,
			 //  "refundNo": "string",
			 //  "returnAmount": 0,
			 //  "serveType": 0,
			 //  "status": 0
			// }


		) {
			// console.log("params", params)
			// commit("setOrderFrom", params)
			return await new Promise((resolve, reject) => {

				http.post('/refund/editRefundState', params).then(res => {

					console.log("买家操作服务单信息成功", res)
					// let data = res.data.data
					// dispatch("getOrderList")
					resolve(res)

				}).catch(err => {
					console.log("买家操作服务单信息失败", err)
					reject(err)
				})
			})
		},
		
		

	}
}
